﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using System.Web.UI.HtmlControls;
using GCELibrary.Current;
using ZF.Model;
using System.Transactions;
using ZF.BLL.ServiceModel;

namespace ZF.WS.service
{
    public partial class fsyw : BLL.Page.PageBase
    {

        [PageArgument(Key = "p",DefaultValue=0)]
        public int IsPub { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Add();
            }
        }

 
        public void InitControls()
        {
       
        }


        public void Add()
        {
            InitControls();
       
        }
        public void AddSubmit(object sender, EventArgs e)
        {
            if (!SiteInfo.ValidateCode(this.tbVCode.Text))
            {
                WarnFactory.CreateWarn(new PageWarnParameter()
                {
                    JscriptMode = true,
                    Link = WarnLink.GoBack,
                    Message = "验证码错误",
                }).Alert();
                return;
            }


            using (var dc = SiteInfo.CreateDBDataContext())
            {

                var srv = new Model.Sys_Service()
                {
                    AddTime = DateTime.Now,
                    IsAcc = false,
                    Type = IsPub == 0 ? (int)ServiceType.FSYW : (int)ServiceType.FSYW1,
                    Json = Newtonsoft.Json.JsonConvert.SerializeObject(new FSYW()
                    {
                        Content = this.tbContent.Text.Replace("\r\n", "<br>"),
                        Type = this.ddlType.SelectedValue,
                        BuyMemberIds = new List<int>(),
                        FSS = this.tbFSS.Text,
                    }),
                    Address = this.tbAddress.Text,
                    Contact = this.tbContact.Text,
                    Email = this.tbEmail.Text,
                    Tel = this.tbTel.Text,
                    Remark = this.tbContent.Text.Replace("\r\n","<br>"),
                    MemberId = SiteInfo.GetCurrentMember() != null ? SiteInfo.GetCurrentMember().MemberId : 0
                };
                SiteInfo.CheckFilterWords(srv);
                try
                {
                    dc.Sys_Service.InsertOnSubmit(srv);
                    dc.SubmitChanges();

                }
                catch (Exception ex)
                {
                    throw WarnFactory.CreateWarn(ex);
                }

                WarnFactory.CreateWarn(new PageWarnParameter()
                {
                    JscriptMode = true,
                    Message = "操作成功",
                    Link = WarnLink.GoBack,
                }).Alert();



            }



        }
    }
}
